package CtrlLayer;
import java.util.ArrayList;
import ModelLayer.*;

public class SessionController
{
    private SessionContainer sessionContainer;
    private ManagerController managerController;

    public SessionController(){
        sessionContainer = SessionContainer.getInstance();
        managerController = new ManagerController();
    }

    public int createSession(){  
        Session sObject = null;
        int index = 0;
        int id = 0;
        while(index < sessionContainer.getSessionList().size()){
            sObject = sessionContainer.getSessionList().get(index); 
            if(sObject.getSessionId()>id)   
                id = sObject.getSessionId();
            index++;
        }
        id++;
        sessionContainer.addSession(new Session(id));
        managerController.createObject();
        return id;
    }

    public void endSession(int sessionId){
        findSession(sessionId).logOut();
    }
    
    public Session findSession(int id){    
        return  sessionContainer.findSessionById(id);
    }
}
